package thread;


// 方法一：继承Thread 类， 重写run方法
class MyThread extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println("hello thread!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("线程结束!");
    }
}

public class demo1 {
    public static void main(String[] args) {
        Thread t = new MyThread();
        System.out.println("线程1启动!");
        t.start();
        System.out.println("主线程结束!");
    }

}
